package com.example.demo.vo;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/*
  分页返回信息封装信息Vo
 */
@Data
@ApiModel("分页结果数据封装")
//注解，添加一个无参数的构造方法，防止spring创建bean时，创建失败，导致异常
@NoArgsConstructor
public class PageVo<T> {

    @ApiModelProperty("页码")
    private long pageNumber;
    @ApiModelProperty("每页大小")
    private  long pageSize;
    @ApiModelProperty("总数据条数")
    private long totalCount;
    @ApiModelProperty("总页数")
    private  long totalPage;
    @ApiModelProperty("返回的查询结果")
    private List<T> records;


    /*
    *创造分页构造方法
     */

    public PageVo(IPage<T> pageResult) {
        this.pageNumber = pageResult.getCurrent();
        this.pageSize = pageResult.getSize();
        this.totalPage = pageResult.getPages();
        this.totalCount = pageResult.getTotal();
        this.records = pageResult.getRecords();
    }
}
